<?php

require_once "dbconnect.php";

$car_type_id = $_POST['car_type_id'];
if( empty($car_type_id) ) $car_type_id = $_GET['car_type_id'];

$start_place = $_POST['start_place'];
if( empty($start_place) ) $start_place = $_GET['start_place'];

$destination_place = $_POST['destination_place'];
if( empty($destination_place) ) $destination_place = $_GET['destination_place'];

$service_city_name = $_POST['service_city_name'];
if( empty($service_city_name) ) $service_city_name = $_GET['service_city_name'];

$max_no_of_passenger = $_POST['max_no_of_passenger'];
if( empty($max_no_of_passenger) ) $max_no_of_passenger = $_GET['max_no_of_passenger'];

$cond = "";

if( $car_type_id != '' ){
	$cond .= "AND car_type_id = '$car_type_id' ";
}

if( $start_place != '' ){
	$cond .= "AND start_place = '$start_place' ";
}

if( $destination_place != '' ){
	$cond .= "AND destination_place = '$destination_place' ";
}

if( $max_no_of_passenger != '' ){
	$cond .= "AND max_no_of_passenger = '$max_no_of_passenger' ";
}

if( $service_city_name != '' ){
	$cond .= "AND service_city_name = '$service_city_name' ";
}
//echo "state_name = ".$state_name."<br>";

$sql = "SELECT * FROM flat_rates WHERE flat_status = '1' $cond";
//$sql = "SELECT * FROM flat_rates WHERE flat_available = '1' $cond";
}
$res = $db->query($sql);

//For debug:
//echo "Total categories found: ".$res->num_rows;
//echo "<br>";

if( $res->num_rows == 0 ){
	echo json_encode(array("status"=>"not found"));
	exit();
}
for( $i=0; $i<$res->num_rows; $i++ ){
	$flat_rate = $res->rows[$i]; 
	$flat_rates[] = $flat_rate;
}
echo json_encode(array("status"=>"ok","flat_rates"=>$flat_rates));

?>
